<div class="clear_both"></div>
<div class="main_container">
<div class="sub_tabs">
<ul class="idTabs"> 
  <li><a href="#list" id="list_tab">List</a></li> 
  <li><a href="#upload" id="upload_tab">Upload</a></li> 
</ul>
</div>
<?php echo form_open('biometric/list');?>
<div class="biometric" id="list">
<div class="clear_both"></div>
<fieldset>
<legend>BIOMETRIC FILES</legend>
<div class="fieldset_container_2">
	<table border="1" cellspacing="0" cellpadding="5" id="biometric_files" class="display">
<thead>
			<tr>
				<th>File Name</th>
				<th>Orig File Name</th>
				<th>Size</th>
				<th>Date Uploaded</th>
				<th>Upload By</th>
				<th>Loaded?</th>
				<th>Action</th>
			</tr>
		</thead>
<?php 
if(isset($lists) && !empty($lists)):?>
<?php foreach($lists as $list) {?>
<tr>
	<td><?php echo $list->file_name?></td>
	<td><?php echo $list->orig_file_name?></td>
	<td><?php echo round($list->file_size/ 1000, 2). " Mb"?></td>
	<td><?php echo DateUtils::formatDate($list->date_created, DateUtils::$FRIENDLY_DATE_FORMAT)?></td>
	<td><?php echo StringUtils::concat(array($list->first_name, $list->middle_name, $list->last_name)); ?></td>
	<td><b><?php echo $list->is_loaded?'Yes':'No'?></b></td>
	<td><a href="javascript:;" class="view" bid="<?php echo $list->id?>">View</a></td>
</tr>
<?php }?>
<?php endif;?>
</table>
</div>

</fieldset>
</div>
<?php echo form_close();?>
</br />
<?php echo form_open_multipart('biometric/upload');?>
<div class="file201" id="upload">
<fieldset>
<legend>UPLOAD</legend>
<?php 
	if(isset($message) && is_array($message)) {
		echo "<p class='error'>{$message['error']}</p>";
	} else if(isset($message)) {
		echo "<p class='error'>{$message}</p>";
	}

?>
<ul>
		<li>
			<div class="list_item">
				<ul>
				<li> <label for="file">Select File: </label>
				<input type="file" name="userfile" id="userfile" size="30" value="" />
				</ul>
			</div>
		</li>
	<li><input type="submit" name="submit" id="submit" value="Upload" ></li>	
<ul>
</fieldset>
</div>
<?php echo form_close();?>
</div>

<script>
$('#biometric_files').dataTable({
	"sPaginationType": "full_numbers",
	"iDisplayLength":25,
	"aaSorting": null
});

$('a.view').click(function(){
	url = '<?php echo base_url()?>biometric/view/' + $(this).attr('bid');
	$.fancybox.open({
		href : url,
		type : 'iframe',
		padding : 10,
		height: '70%',
		width: 600,
		autoSize	: false,
		helpers:  {
			overlay : {
				opacity  : 0.4,
				closeClick: false
			}
	    }
	});
})

<?php if(isset($message)): ?>
$('#upload_tab').addClass('selected');
<?php endif;?>

$('#submit').click(function(){
	var ret = validateFileName();
	if(ret == false) return false;
});

function validateFileName(){
	$userfile = $('#userfile').val();
	if($userfile == '') {
		alert('Please specify valid xls file.');
		return false;
	} else {
		var items = $userfile.split("\\");
		$filename = items[items.length - 1];
		if($filename != ""){
			$names = $filename.split(".");
			if($names.length > 2 ) {
				alert("Filename will contain only 1 ('.'). ");
				return false;
			}
		}
		
		//return true;
	}
	//return true;
}
</script>
